package cn.edu.zufe.mjt.insight;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool pool = new MyThreadPool(2, 6, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(2), new LogAndDiscardRejectHandle());
        for (int i = 0; i < 50; i++) {
            int finalI = i;
            pool.execute(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "任务：" + finalI);
            });
            Thread.sleep(100); // 控制提交频率
        }

        System.out.println("主线程没有阻塞");

        pool.execute(() -> {
            System.out.println("模拟后续的任务。");
        });
    }
}